<template>
	<view class="app">
		<view class="app-container">
			<view class="dots">
				<view class="cu-list menu">
					<view class="cu-item">
						<view class="content text-default text-sm">订单状态</view>
						<view class="action text-grey text-sm">
							{{ data.status | filterStatus }}
							<text v-if="item.print_order_status && item.print_order_status === 6">{{ item.print_order_status === 6 && navList[tabIndex].type === 3 ? '( 文件已打印 )' : '' }}</text>
						</view>
					</view>
					<view class="cu-item" v-for="(type, index) in orderItems" :key="index" v-if="data[type.key] && data[type.key] !== '0000-00-00 00:00:00'">
						<view class="content text-default text-sm">{{ type.name }}</view>
						<view class="action text-grey text-sm">{{ data[type.key] || '暂无' }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
import { getDemandOrderInfo } from '@/api/community.js';
export default {
	computed: {
		...mapGetters(['isIphoneX'])
	},
	filters: {
		filterStatus(value) {
			const orderStates = {
				0: '未支付',
				1: '等待接单',
				2: '已取消',
				3: '配送中',
				4: '已送达',
				5: '申诉中',
				6: '退款中',
				7: '已退款',
				8: '已确认收货',
				9: '特殊订单'
			};
			return orderStates[value];
		}
	},
	data() {
		return {
			data: {},
			orderItems: [
				{
					name: '所在区域',
					key: 'area_name'
				},
				{
					name: '需求类型',
					key: 'demand_type_name'
				},
				{
					name: '订单时间',
					key: 'create_time'
				},
				{
					name: '接单时间',
					key: 'order_time'
				},
				{
					name: '提取码',
					key: 'code'
				},
				{
					name: '联系电话',
					key: 'telephone'
				},
				{
					name: '所在区域',
					key: 'area_name'
				},
				{
					name: '收货地址',
					key: 'address'
				},
				{
					name: '快递收件人',
					key: 'express_addressee_name'
				},
				{
					name: '快递公司',
					key: 'courier_services_company_name'
				},
				{
					name: '派送时间',
					key: 'delivery_time'
				},
				{
					name: '快递短信',
					key: 'express_message'
				},
				{
					name: '需求描述',
					key: 'describe'
				},
				{
					name: '骑手电话',
					key: 'take_order_telephone'
				},
				{
					name: '商品总价',
					key: 'price'
				},
				{
					name: '实付款',
					key: 'actual_price'
				},
				{
					name: '包含小费',
					key: 'tip'
				}
			]
		};
	},
	onLoad(options) {
		this.demand_order_id = options.demand_order_id;
		this.getDemandOrderInfoEvent();
	},
	methods: {
		getDemandOrderInfoEvent() {
			getDemandOrderInfo({
				demand_order_id: this.demand_order_id
			}).then(res => {
				this.data = res.result;
			});
		},
		cancelEvent() {},
		/**
		 * 骑手确认送达
		 * @param {Object} item 选择的订单
		 */
		confirmDeliveryEvent(item) {
			confirmDelivery({
				demand_order_id: item.demand_order_id
			}).then(res => {
				uni.showModal({
					title: '确认已送达',
					content: '等待需求者确认收货或三天后自动确认收货，感谢您和需求者的互爱互助',
					showCancel: false
				});
			})
		},
		/**
		 * 用户确认收货
		 * @param {Object} item 选择的订单
		 */
		userConfirmDeliveryEvent(item) {
			wechatUserConfirmDelivery({
				demand_order_id: item.demand_order_id
			}).then(res => {
				uni.showModal({
					title: '确认已送达',
					content: '钱款会自动打入骑手账户，感谢您和骑手的互爱互助',
					showCancel: false
				});
			})
		}
	}
};
</script>

<style lang="scss" scoped>
.cu-item {
	min-height: 80rpx !important;
	&::after {
		border: none;
	}
	.content {
		font-size: 24rpx !important;
	}
	.action {
		width: 70%;
		text-align: right;
	}
}
.dots {
	margin: 20rpx 30rpx;
	border: 1px dotted #bbbbbb;
}
</style>
